<?php







function curl_get_contents($url){
	$ch=curl_init();
	curl_setopt($ch, CURLOPT_URL, $url);                //设置访问的url地址
	// curl_setopt($ch,CURLOPT_HEADER,1);               //是否显示头部信息
	curl_setopt($ch, CURLOPT_TIMEOUT, 5);               //设置超时
	curl_setopt($ch, CURLOPT_USERAGENT, $_SERVER['HTTP_USER_AGENT']);   //用户访问代理 User-Agent
	curl_setopt($ch, CURLOPT_REFERER,$_SERVER['HTTP_HOST']);        //设置 referer
	curl_setopt($ch,CURLOPT_FOLLOWLOCATION,1);          //跟踪301
	curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);        //返回结果
	$r=curl_exec($ch);
	curl_close($ch);
	return $r;
}
/**
 * some_func
 * 验证码检查
 *
 * @access public
 * @param mixed $code 验证码
 * @param mixed $id 验证码标识
 * @since 1.0
 * @return array 返回数组参数
 */
function check_verify($code, $id = ""){
    $verify = new \Think\Verify();
    return $verify->check($code, $id);
}

define('PAGE_IMG_SUM', 60);  //每页显示数据量
define('PAGE_DB_SUM', 15);  //每页显示数据量
define('PAGE_BTN_SUM', 5);  //每页显示的分页按钮数量


function  sum_zlf($a,$b,$c,$d,$e){
	
	$res=($a-$b)/$c*$d*$e/100;
	
	return round($res,2);
}
/**
 * some_func
 * 分页输出
 *
 * @access public
 * @param mixed $dbsum 总数据量
 * @param mixed $path 页面地址
 * @param mixed $index 当前页码
 * @since 1.0
 * @return array 返回数组参数
*/

function set_paging($dbsum, $path, $index=1){
    $strPage = '';

    $starId = 0;  //页按钮开始位置
    $endId = 0;  //页按钮结束位置
    //计算页数
    $pageSum = 1;  //页数，默认为1页
    if($dbsum > 0) {
        if($dbsum > PAGE_DB_SUM) {
            $x = intval($dbsum / PAGE_DB_SUM);
            $y= $dbsum % PAGE_DB_SUM;
            if($y > 0)
                $pageSum = $x + 1;
            else
                $pageSum = $x;
        }
    }

    if($index > $pageSum)
        $index = $pageSum;

    //计算滚动起始位置
    //如果页数小于分组的条件
    if($pageSum < PAGE_BTN_SUM) {
        $starId = 1;
        $endId = $pageSum;
    } else {
        //如果是第一页
        if($index == 1) {
            $starId = 1;
            $endId = PAGE_BTN_SUM;
        } else {
            $cp =  intval(PAGE_BTN_SUM / 2); //中间按钮基数
            $ep = PAGE_BTN_SUM - $cp; //右边基数

            $ls = $index - $ep + 1;
            $rs = $index + $cp;
            //如果大于中间数
            if($ls > 0 && $rs<$pageSum) {
                $starId = $ls;
                $endId = $rs;
            } else {
                if($ls > 0 & $rs>=$pageSum) {
                    $starId = $pageSum - PAGE_BTN_SUM + 1;
                    $endId = $pageSum;
                } else {
                    $starId = 1;
                    $endId = PAGE_BTN_SUM;
                }
            }
        }
    }

    $strPage .= '   <ul class="pagination pagination-group">' . "\r\n";
    if(1 == $index) {
        $strPage .= '       <li class="active"><a href="javascript:void(0);">首页</a></li>' . "\r\n";
        $strPage .= '       <li class="active"><a href="javascript:void(0);">上一页</a></li>' . "\r\n";
    } else {
        $strPage .= '       <li><a href="' . $path . '1.html">首页</a></li>' . "\r\n";
        $strPage .= '       <li><a href="' . $path . '' . ($index-1) . '.html">上一页</a></li>' . "\r\n";
    }
    for ($i=$starId; $i<=$endId; $i++) {
        if($index==$i) {
            $strPage .= '       <li class="active"><a href="javascript:void(0);">' . $i . '</a></li>' . "\r\n";
        } else {
            $strPage .= '       <li><a href="' . $path . '' . $i . '.html">' . $i . '</a></li>' . "\r\n";
        }
    }
    if($endId == $index) {
        $strPage .= '       <li class="active"><a href="javascript:void(0);">下一页</a></li>' . "\r\n";
        $strPage .= '       <li class="active"><a href="javascript:void(0);">尾页</a></li>' . "\r\n";
    } else {
        $strPage .= '       <li><a href="' . $path . '' . ($index+1) . '.html">下一页</a></li>' . "\r\n";
        $strPage .= '       <li><a href="' . $path . '' . $pageSum . '.html">尾页</a></li>' . "\r\n";
    }
    $strPage .= '   </ul>' . "\r\n";
    return $strPage;
}



function msubstr($str, $start=0, $length, $charset="utf-8", $suffix=true)
{
    if(function_exists("mb_substr")){
        if ($suffix && strlen($str)>$length)
            return mb_substr($str, $start, $length, $charset)."...";
        else
            return mb_substr($str, $start, $length, $charset);
    }
    elseif(function_exists('iconv_substr')) {
        if ($suffix && strlen($str)>$length)
            return iconv_substr($str,$start,$length,$charset)."...";
        else
            return iconv_substr($str,$start,$length,$charset);
    }
    $re['utf-8']   = "/[\x01-\x7f]|[\xc2-\xdf][\x80-\xbf]|[\xe0-\xef][\x80-\xbf]{2}|[\xf0-\xff][\x80-\xbf]{3}/";
    $re['gb2312'] = "/[\x01-\x7f]|[\xb0-\xf7][\xa0-\xfe]/";
    $re['gbk']    = "/[\x01-\x7f]|[\x81-\xfe][\x40-\xfe]/";
    $re['big5']   = "/[\x01-\x7f]|[\x81-\xfe]([\x40-\x7e]|\xa1-\xfe])/";
    preg_match_all($re[$charset], $str, $match);
    $slice = join("",array_slice($match[0], $start, $length));
    if($suffix) return $slice."…";
    return $slice;
}

/**
 * 导出数据为excel表格
 *@param $data    一个二维数组,结构如同从数据库查出来的数组
 *@param $title   excel的第一行标题,一个数组,如果为空则没有标题
 *@param $filename 下载的文件名
 *@examlpe
 $stu = M ('User');
 $arr = $stu -> select();
 exportexcel($arr,array('id','账户','密码','昵称'),'文件名!');
 */
function exportexcel($data=array(),$title=array(),$filename='report'){
	header("Content-type:application/vnd.ms-excel;charset=utf8");
    header("Content-Type:text/html;charset=utf8");
    header("Content-type:application/octet-stream");
    header("Accept-Ranges:bytes");
    //header("Content-type:application/vnd.ms-excel");  
    header("Content-Disposition:attachment;filename=".$filename.".xls");
    header("Pragma: no-cache");
    header("Expires: 0");
    //导出xls 开始
    if (!empty($title)){
        foreach ($title as $k => $v) {
            $title[$k]=iconv("UTF-8", "GB2312",$v);
        }
        $title= implode("\t", $title);
        echo "$title\n";
    }
    if (!empty($data)){
        foreach($data as $key=>$val){
            foreach ($val as $ck => $cv) {
                $data[$key][$ck]=iconv("UTF-8", "GB2312", $cv);
            }
            $data[$key]=implode("\t", $data[$key]);
            
        }
        echo implode("\n",$data);
    }
}

/**
 * 导出数据为csv
 *@param $data  CSV格式数据
 *@param $filename 下载的文件名
 *@examlpe
 */
function exportcsv($data,$filename){
     header("pragma: no-cache");
     header("Cache-Control: no-cache, must-revalidate");
     header("expires: Wed, 26 Feb 1997 08:21:57 GMT");
     header("Content-type:application/vnd.ms-excel");
     header("Content-Disposition:attachment;filename=".$filename.".csv");
     header("Expires: 0");
     header("Pragma: public");
     header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
     header("Cache-Control: public");
     
     
     echo(mb_convert_encoding($data,"gb2312","UTF-8"));
}



/**
 * 邮件发送函数
 * @param $host  smtp地址
 * @param $port  smtp端口
 * @param $smtpmail  smtp邮箱
 * @param $smtpid  smtp账号
 * @param $smtppwd  smtp密码
 * @param $webname  发件人
 * @param $to  要发送的地址
 * @param $title 邮件标题
 * @param $content 邮件内容
 * @return boolean
 */
function sendMail($host, $port, $smtpmail, $smtpid, $smtppwd, $fromname, $to, $title, $content) {
     
    Vendor('PHPMailer.PHPMailerAutoload');      
    $mail = new PHPMailer(false); //实例化
    $mail->IsSMTP(); // 启用SMTP
    $mail->Host= $host; //smtp服务器的名称（这里以QQ邮箱为例）
    $mail->Port = $port;
    $mail->SMTPAuth = true; //启用smtp认证
    $mail->Username = $smtpid; //你的邮箱名
    $mail->Password = $smtppwd; //邮箱密码
    $mail->From = $smtpmail; //发件人地址（也就是你的邮箱地址）
    $mail->FromName = $fromname; //发件人姓名
    $mail->AddAddress($to,"");
    $mail->WordWrap = 50; //设置每行字符长度
    $mail->IsHTML(true); // 是否HTML格式邮件
    $mail->CharSet="utf-8"; //设置邮件编码
    $mail->Subject =$title; //邮件主题
    $mail->Body = $content; //邮件内容
    $mail->AltBody = html_specials($content); //邮件正文不支持HTML的备用显示
    return($mail->Send());
}

function sizecount($filesize) {
 if($filesize >= 1073741824) {
  $filesize = round($filesize / 1073741824 * 100) / 100 . ' gb';
 } elseif($filesize >= 1048576) {
  $filesize = round($filesize / 1048576 * 100) / 100 . ' mb';
 } elseif($filesize >= 1024) {
  $filesize = round($filesize / 1024 * 100) / 100 . ' kb';
 } else {
  $filesize = $filesize . ' bytes';
 }
 return $filesize;
}

  

/****************************************
 * 插入日志
*****************************************/
function add_log($admin_name, $log_text) {
	$array['admin_name'] = $admin_name;
	$array['log_text'] = $log_text;
	$array['log_time'] = time();
	D('Syslog')->insert($array);
}
/****************************************
 * 检索分类选择类型
*****************************************/
function gc_type_for($types, $type_id) {
	if($types == '') {
		return 0;
	} else {
		$type_array = explode(',', $types);
		$ax = 0;
		for($i=0; $i<count($type_array); $i++) {
			$typeid = intval($type_array[$i]);
			if($typeid == $type_id) {
				$ax = 1;
				break;
			}
		}
	    return $type_id;
	}
}


/**************************************************************
 *  生成指定长度的随机码。
*  @param int $length 随机码的长度。
*  @access public
**************************************************************/


/**************************************************************
*  将物理路径转为虚拟路径。
*  @param string $physicalPpath 物理路径。
*  @access public
**************************************************************/
function toVirtualPath($physicalPpath)
{
	$virtualPath = str_replace($_SERVER['DOCUMENT_ROOT'], "", $physicalPpath);
	$virtualPath = str_replace("\\", "/", $virtualPath);
	return $virtualPath;
}



function getExpress($excode, $number) {
	$host = 'http://ali-deliver.showapi.com';
	$path = '/showapi_expInfo';
	$method = 'GET';
	$appcode = C('WL_APPCODE');
	$headers = array();
	array_push($headers, 'Authorization:APPCODE ' . $appcode);
	$querys = 'com='.$excode.'&nu='.$number;
	$bodys = '';
	$url = $host . $path . '?' . $querys;
	
	$curl = curl_init();
	curl_setopt($curl, CURLOPT_CUSTOMREQUEST, $method);
	curl_setopt($curl, CURLOPT_URL, $url);
	curl_setopt($curl, CURLOPT_HTTPHEADER, $headers);
	curl_setopt($curl, CURLOPT_FAILONERROR, false);
	curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
	curl_setopt($curl, CURLOPT_HEADER, false);
	if (1 == strpos("$".$host, "https://"))
	{
		curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
		curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false);
	}
	$str_data = curl_exec($curl);
	$data = json_decode($str_data,true);
	if($data['showapi_res_body']['ret_code']==0) {
		$list1 = $data['showapi_res_body']['data'];
		$list2 = array();
		$n = count($list1);
		for($i=0; $i<count($list1); $i++) {
			$n--;
			$list2[$i] = $list1[$n];
		}
		$data['showapi_res_body']['data'] = $list2;
	}
	return $data;
}

function object_array($array) {
	if(is_object($array)) {
		$array = (array)$array;
	} if(is_array($array)) {
		foreach($array as $key=>$value) {
			$array[$key] = object_array($value);
		}
	}
	return $array;
}


/**
 * 获取微信Token
 * @return Ambigous <unknown, array>  返回状态、Token、有效期
 */
function request_opentoken() {
	$wx_appid = C('WX_APPID');
	$wx_appsecret = C('WX_APPSECRET');

	$token_array = D('System')->find_query('wx');
	$token = $token_array['wx_access_token'];
	$expires_time = $token_array['wx_expires_time'];
	$tm = time();

	if(empty($token)) {
		$url = 'https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=' . $wx_appid . '&secret=' . $wx_appsecret;
		$contents = file_get_contents($url);
		$array = object_array(json_decode($contents));
		$token = $array['access_token'];
		$expires_in = $array['expires_in'];
		$expires_time = time() + $expires_in;
		D('System')->update('wx_access_token', $array['access_token']);
		D('System')->update('wx_expires_time', $expires_time);
	} else {
		if($expires_time < $tm) {
			$url = 'https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=' . $wx_appid . '&secret=' . $wx_appsecret;
			$contents = file_get_contents($url);
			$array = object_array(json_decode($contents));
			$token = $array['access_token'];
			$expires_in = $array['expires_in'];
			$expires_time = time() + $expires_in;
			D('System')->update('wx_access_token', $array['access_token']);
			D('System')->update('wx_expires_time', $expires_time);
		}
	}
	return $token;
}

/**
 * 发送微信消息模板
 * @param unknown $params 消息数据
 * @return array 返回值
 */
function send_wx_msg($params) {
	$token = request_opentoken();

	$url = 'https://api.weixin.qq.com/cgi-bin/message/template/send?access_token=' . $token;
	$data = json_encode($params);
	$content = array('http' => array('method' => 'POST', 'header'  => 'Content-type: application/x-www-form-urlencoded','content' => $data ));
	$dbcontent  = stream_context_create($content);
	$contents = file_get_contents($url, false, $dbcontent);
	$array = object_array(json_decode($contents));
	return $array;
}

/**
 * 发送验证码短信
 * @param unknown $params
 * @return array
 */
function send_sms_code($mobile) {
	$result['status'] = 'n';
    $result['info'] = '';
	$AppKey = D('System')->find_row_by('sms_id');
	$AppSecret = D('System')->find_row_by('sms_pass');

    Vendor('Sms.Wysms');
    $wyama = new \Wysms($AppKey,$AppSecret,'curl');
    $ret = $wyama->sendSmsCode($mobile,'');
    if($ret['code'] == 200) {
    	$result['status'] = 'y';
    	$result['info'] = '验证码发送成功';
    } else {
    	$result['status'] = 'n';
    	$result['info'] = '验证码发送失败,' . $wyama->getErroMsg($ret['code']);
    }
	return  $result;
}

/**
 * 校验验证码
 * @param unknown $params
 * @return array
 */
function verifycode_sms_code($mobile, $code) {
	$result['status'] = 'n';
    $result['info'] = '';
	$AppKey = D('System')->find_row_by('sms_id');
	$AppSecret = D('System')->find_row_by('sms_pass');
	
	Vendor('Sms.Wysms');
	$wyama = new \Wysms($AppKey,$AppSecret,'curl');
	$ret = $wyama->verifycode($mobile,$code);
	if($ret['code'] == 200) {
    	$result['status'] = 'y';
    	$result['info'] = '验证码验证成功';
    } else {
    	$result['status'] = 'n';
    	$result['info'] = '验证码验证失败,' . $wyama->getErroMsg($ret['code']);
    }
	return  $ret;
}

/**
 * 发送验证码短信
 * @param unknown $params
 * @return array
 */
function send_sms_msg($templateid, $mobile, $params) {
	//是否开启短信通知
	$smsopen = D('System')->find_row_by('sms_open');
	$sms_open = intval($smsopen);
	$result['status'] = 'n';
    $result['info'] = '';
    $phone = array($mobile);

	if($sms_open > 0) {
		$AppKey = D('System')->find_row_by('sms_id');
		$AppSecret = D('System')->find_row_by('sms_pass');

		Vendor('Sms.Wysms');
		$wyama = new \Wysms($AppKey,$AppSecret,'curl');
		$ret = $wyama->sendSMSTemplate($templateid, $phone, $params);
		$str_code = $ret['code'] . '';
		if($ret['code'] == 200) {
	    	$result['status'] = 'y';
	    	$result['info'] = '短信发送成功';
	    } else {
	    	$result['status'] = 'n';
	    	$result['info'] = '短信发送失败,' . $wyama->getErroMsg($str_code);
	    }
	} else {
		$result['status'] = 'n';
		$result['info'] = '系统已经关闭了短信发送功能';
	}
	return  $result;
}

/**
 * 预购处理
 * @param unknown $memDB 会员数据
 * @param unknown $zlfhj 转乐分合计
 */
function mem_yg_fl($memDB, $total_zlcent) {
	$pm_array = explode(";",$memDB['pay_money']);
	$pb_array = explode(";",$memDB['pay_back_zlf']);
	$pre_money = floatval($pm_array[0]);
	$back_limt = intval($pb_array[0]);
	
	if($total_zlcent >= $back_limt) {
		$memArray['member_id'] = $memDB['member_id'];
		$moneys = $memDB['moneys'] + $pre_money;
		$memArray['moneys'] = moneys;
		if(count($pm_array) > 1) {
			$pmoney = '';
			$plimt = '';
			for($i=1; $i<count($pm_array); $i++) {
				if($i == 1) {
					$pmoney = $pm_array[1];
					$plimt = $pb_array[1];
				} else {
					$pmoney += ',' . $pm_array[$i];
					$plimt += ',' . $pb_array[$i];
				}
			}
			$memArray['pay_money'] = $pmoney;
			$memArray['pay_back_zlf'] = $plimt;
			D('Member')->update($memArray);
			
			$paydb['member_id'] = $memDB['member_id'];
			$paydb['username'] = $memDB['username'];
			$paydb['payments_type'] = '收入';
			$paydb['item_type'] = '预购分销返款';
			$paydb['moneys'] = $pmoney;
			$paydb['item_code'] = '';
			$paydb['add_time'] = time();
			D('MemberPayments')->insert($paydb);
		} else {
			$memArray['is_paygrade'] = 0;
			$memArray['pay_money'] = '';
			$memArray['pay_back_zlf'] = '';
			D('Member')->update($memArray);
		}
	}
}

function mem_up_tc($member_id) {
	$mem = D('Member')->find_row_byid($member_id);
	$username = $mem['username'];
	$weixin_id = $mem['weixin_id'];
	$nick_name = $mem['nick_name'];
	$levels_id = $mem['levels_id'];
	$grade_id = $mem['grade_id'];
	$grade_name = $mem['grade_name'];
	$total_zlcent = intval($mem['total_zlcent']);
	
	$up_grade_id = 0;
	if($grade_id < 4) {
		$up_grade_id = $grade_id + 1;
		$gd = D('MemberGrade')->find_row_byid($up_grade_id);
		$up_grade_name = $gd['grade_name'];
		$up_zlf = intval($gd['update_cent']);
		if($total_zlcent >= $up_zlf) { //达到升级条件
			
			D('Member')->update_grade($member_id, $up_grade_id, $up_grade_name);
			
			//发送消息
			$msg['message_id'] = uniqid() . time() . mt_rand(10000, 99999);
			$msg['member_id'] = $member_id;
			$msg['title'] = '您的会员等级提升了';
			$msg['content'] = '尊敬的'. $nick_name .',您已达到分销升级的等级资格，您已经由原等级【'. $grade_name .'】升级未【' . $up_grade_name . '】，感谢您的支持。';
			$msg['send_time'] = time();
			$msg['is_read'] = 0;
			D('Message')->insert_sign($msg);
				
			//发送微信消息
			$domain = C('WX_HOST');
				
			$data['touser'] = $weixin_id;
			$data['template_id'] = 'L1KfPPvZjehCV-Ud3zXc551-uIgIo1z0tHJML3FElLM';
			$data['url'] = $domain . '/weixin/member/index.html';
			$data['data']['first']['value'] = '尊敬的'. $nick_name .', 恭喜你成功升级为' . $up_grade_name;
			$data['data']['first']['color'] = '#000000';
			$data['data']['keyword1']['value'] = $username;
			$data['data']['keyword1']['color'] = '#777777';
			$data['data']['keyword2']['value'] = '永久生效';
			$data['data']['keyword2']['color'] = '#777777';
			$data['data']['remark']['value'] = '感谢您的支持与厚爱，如遇到问题，请与我们联系。';
			$data['data']['remark']['color'] = '#000000';
			send_wx_msg($data);
			
			////是否开启升级提成
			$open_up_cent = D('System')->find_row_by('open_up_cent');
			$is_open = intval($open_up_cent);
			
			if($is_open == 1) {
				if($levels_id > 0) {
					$lev = D('Member')->find_row_byid($levels_id);
					$perce_update = $lev['grade']['perce_update'];
					$tc_zlf = intval($total_zlcent / 100 * $perce_update);
					$lev_m['member_id'] = $levels_id;
					$lev_m['zlcent'] = $lev['zlcent'] + $tc_zlf;
					$lev_m['total_zlcent'] = $lev['total_zlcent'] + $tc_zlf;
					D('Member')->update($lev_m);
				}
				
				if($levels_id > 0) {
					mem_up_tc($levels_id);
				}
			}
		}
	}
}

/**
 * 获取当天是本月的第几周
 * 未简化版
 */
function get_week(){
	$first_mouth = date('Y-m-01', strtotime(date("Y-m-d")));//本月第一天
	$last_mouth = date('d', strtotime("$first_mouth +1 month -1 day"));//本月天数
	$now_time = date('d',time());//获取今天的日期
	$week = date('w',strtotime($first_mouth));//获取本月第一天周几
	//获取本月第一周有多少天
	switch($week){
		case 0;
		$first_week = 1;
		break;
		case 1;
		$first_week = 7;
		break;
		case 2;
		$first_week = 6;
		break;
		case 3;
		$first_week = 5;
		break;
		case 4;
		$first_week = 4;
		break;
		case 5;
		$first_week = 3;
		break;
		case 6;
		$first_week = 2;
		break;
	}
	$surplus_day = $last_mouth - $first_week;//获取本月除去第一周剩余的天数
	$d = ceil($surplus_day/7);//获取本月除了第一周还剩余多少周
	$w = $first_week +1;//本月第二周的第一天
	$i = '0';
	$d = '2';
	for($w;$w<=$last_mouth;$w++){
		$i++;
		if($i == '8'){
			$i = '1';
			$d++;
		}
		// $data[$d][$i] = $w;
		if($now_time == $w){
			return $d;
		}
	}

}
//生成序列号BYqiu
function get_web_no ()
{
    $rst=M("WebConfig")->field("no")->order("add_time desc")->find();
//                    echo M("webcong")->getLastSql();
    $no=1000000000;
//    var_dump($rst);exit;
    if($rst){
        $no=(int)$rst["no"]+1;
    }
        return $no;
}
 //秘钥Byqiu
function get_secret_key ()
{
    $no= get_web_no();
    $key=$no.time();
    $realkey= md5($key);
    return $realkey;
}

//二维数组转一维
//5.5以上同array_column
function i_array_column($input, $columnKey, $indexKey=null){
    if(!function_exists('array_column')){ 
        $columnKeyIsNumber  = (is_numeric($columnKey))?true:false; 
        $indexKeyIsNull            = (is_null($indexKey))?true :false; 
        $indexKeyIsNumber     = (is_numeric($indexKey))?true:false; 
        $result                         = array(); 
        foreach((array)$input as $key=>$row){ 
            if($columnKeyIsNumber){ 
                $tmp= array_slice($row, $columnKey, 1); 
                $tmp= (is_array($tmp) && !empty($tmp))?current($tmp):null; 
            }else{ 
                $tmp= isset($row[$columnKey])?$row[$columnKey]:null; 
            } 
            if(!$indexKeyIsNull){ 
                if($indexKeyIsNumber){ 
                  $key = array_slice($row, $indexKey, 1); 
                  $key = (is_array($key) && !empty($key))?current($key):null; 
                  $key = is_null($key)?0:$key; 
                }else{ 
                  $key = isset($row[$indexKey])?$row[$indexKey]:0; 
                } 
            } 
            $result[$key] = $tmp; 
        } 
        return $result; 
    }else{
        return array_column($input, $columnKey, $indexKey);
    }
}